package com.huang.springcloud.controller;

import com.huang.springcloud.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class DeptController {

    @Autowired
    RestTemplate restTemplate;

//    private static final String oneUrl = "http://localhost:8001";
    private static final String oneUrl = "http://SPRINGCLOUD-PROVIDER";

    @PostMapping("/consumer/dept/add")
    public int addDept(@RequestBody Dept dept) {
        return restTemplate.postForObject(oneUrl + "/dept/add", dept, int.class);
    }

    @GetMapping("/consumer/dept/{id}")
    public Dept getById(@PathVariable("id") int id) {
        return restTemplate.getForObject(oneUrl + "/dept/" + id, Dept.class);
    }

    @GetMapping("/consumer/dept/list")
    public List<Dept> getList() {
        return restTemplate.getForObject(oneUrl + "/dept/list", List.class);
    }
}
